package com.y.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 返回结果集
 * @author: Yjh
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class R {
    private Integer   code;
    private String    message;
    private Object    data;

    public R(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }
    public R(RHttpStatusEnum RHttpStatusEnum) {
        this.code = RHttpStatusEnum.getCode();
        this.message = RHttpStatusEnum.getMessage();
        this.data = null;
    }

    public static R success(){
        R r = new R();
        r.code = 200;
        r.data = null;
        return r;
    }

    public static R success(String message){
        R r = new R();
        r.code = 200;
        r.data = null;
        r.message = message;
        return r;
    }
    public static R success(RHttpStatusEnum RHttpStatusEnum){
        return new R(RHttpStatusEnum.getCode(), RHttpStatusEnum.getMessage());
    }

    public static R error(){
        R r = new R();
        r.code = -200;
        r.data = null;
        return r;
    }

    public static R error(String message){
        R r = new R();
        r.code = -200;
        r.data = null;
        r.message = message;
        return r;
    }

    public static R error(RHttpStatusEnum RHttpStatusEnum){
        return new R(RHttpStatusEnum.getCode(), RHttpStatusEnum.getMessage());
    }


}
